package com.likou;

/**
 * Author: 陈桂明
 * Date: 2025/4/9 17:19
 * Description: q153
 */
public class q153 {
    // public int findMin(int[] nums) {
    //     if (nums[0] <= nums[nums.length - 1]) {
    //         return nums[0];
    //     }
    //
    //     int low = 0;
    //     int high = nums.length - 1;
    //     int mid;
    //
    //     while (low < high) {
    //         mid = (low + high) / 2;
    //
    //         if (nums[mid] >= nums[0]) {
    //             low = mid + 1;
    //         } else {
    //             high = mid;
    //         }
    //     }
    //
    //     return nums[low];
    // }

    public int findMin(int[] nums) {
        int low = 0;
        int high = nums.length - 1;
        int mid;

        while (low < high) {
            mid = (low + high) / 2;

            if (nums[mid] < nums[high]) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        return nums[low];
    }
}
